package cn.yunlang.zhangZhongFei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.yunlang.zhangZhongFei.entity.AwardMessage;
import cn.yunlang.zhangZhongFei.mapper.AwardMessageMapper;
import cn.yunlang.zhangZhongFei.service.AwardMessageService;
import cn.yunlang.zhangZhongFei.vo.response.R;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 抽检消息记录表 服务实现类
 *
 * @author ·
 * @since 2025-05-27 14:23:39
 */
@Service
public class AwardMessageServiceImpl extends ServiceImpl<AwardMessageMapper, AwardMessage>
    implements AwardMessageService {

  @Override
  public R<IPage<AwardMessage>> pageAwardMessages(
      Integer pageNo, Integer pageSize, String message) {
    if (pageNo == null || pageSize == null) {
      return R.error(400, "分页参数不能为空");
    }
    if (pageNo < 1) {
      pageNo = 1;
    }
    if (pageSize < 1) {
      pageSize = 10;
    }
    LambdaQueryWrapper<AwardMessage> wrapper = new LambdaQueryWrapper<>();
    wrapper.like(StringUtils.hasText(message), AwardMessage::getText, message);
    wrapper.orderByDesc(AwardMessage::getCreateTime);
    Page<AwardMessage> page = new Page<>(pageNo, pageSize);
    IPage<AwardMessage> result = this.page(page, wrapper);
    return R.success(result);
  }
}
